<template>
  <!-- 修改手机号弹窗 -->
  <el-dialog
    v-model="editPhoneDialogVisible"
    class="phone-dialog"
    style="width: 414px; height: auto; padding: 0"
    align-center
    :show-close="false"
  >
    <!-- 头部 -->
    <template #header>
      <div class="custom-header">
        <span class="dialog-title">手机号码</span>
        <i class="el-icon-close close-btn" @click="editPhoneDialogVisible = false">
          <el-icon><Close /></el-icon>
        </i>
      </div>
    </template>
    <div class="tab-box">
      <div
        v-for="(item, index) in list"
        :key="index"
        class="item"
        @click="selectedTab = item.value"
      >
        <span :class="{ text: true, 'text-active': item.value === selectedTab }">
          {{ item.label }}
        </span>
        <span v-if="item.value === selectedTab" class="line"></span>
      </div>
    </div>

    <div v-if="selectedTab === 1" class="dialog-content">
      <div class="current-phone">当前手机号：131****2910</div>
      <div class="verify-input">
        <input v-model="verifyCode" placeholder="请输入验证码" />
        <span class="btn">发送验证码</span>
      </div>
    </div>
    <div v-if="selectedTab === 2" class="dialog-content">
      <div class="modify-input">
        <input v-model="newPhone" placeholder="请输入新手机号码" />
      </div>
      <div class="verify-input">
        <input v-model="verifyCode" placeholder="请输入验证码" />
        <span class="btn">发送验证码</span>
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button class="cancel-btn" @click="editPhoneDialogVisible = false">取消</el-button>
        <el-button class="confirm-btn" type="primary" @click="handleConfirm">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts">
export default {
  name: "editPhone",
};
</script>
<script setup lang="ts">
import {
  ref,
  // watch
} from "vue";

const verifyCode = ref("");
// watch(verifyCode, (newValue, oldValue) => {
//   console.log(`值从 ${oldValue} 变为了 ${newValue}`);
//   console.log("--", verifyCode.value);
// });

const editPhoneDialogVisible = ref(false);
// const activeDialogTab = ref("auth");

const selectedTab = ref(1);
const list = ref([
  {
    label: "手机号认证",
    value: 1,
  },
  {
    label: "手机号修改",
    value: 2,
  },
]);

// 暴露弹窗
const openDialog = () => {
  editPhoneDialogVisible.value = true;
};

defineExpose({
  openDialog,
});

const handleConfirm = () => {
  editPhoneDialogVisible.value = false;
};
</script>

<style lang="scss" scoped>
.phone-dialog {
  background: #ffffff;
  border-radius: 9px 9px 9px 9px;
  // background: lightsalmon;
  .tab-box {
    padding: 28px 0;
    display: flex;
    justify-content: center;
    gap: 24px;
    cursor: default;
    .item {
      // background: lightblue;

      display: flex;
      align-items: center;
      flex-direction: column;
      .text {
        font-size: 14px;
        color: #4e5969;
      }
      .text-active {
        color: #3c80ff;
      }
      .line {
        margin-top: 4px;
        width: 25px;
        height: 2px;
        background: #3c80ff;
      }
    }
  }
  .custom-header {
    position: relative;
    display: flex;
    align-items: center;
    padding: 32px 24px;
    border-bottom: 1px solid #e0e0e0;

    .dialog-title {
      font-size: 16px;
      color: rgba(0, 0, 0, 0.9);
    }

    .close-btn {
      position: absolute;
      right: 20px;
      top: 50%;
      transform: translateY(-50%);
      cursor: pointer;
      font-size: 16px;
      color: #999;
      transition: color 0.2s;

      &:hover {
        color: #666;
      }
    }
  }

  .dialog-content {
    padding: 10px 0;
    width: 241px;
    margin: 0 auto;

    .current-phone {
      color: #666;
      margin-bottom: 20px;
      font-size: 14px;
      padding: 5px 0;
    }

    .verify-input {
      width: 100%;
      height: 32px;
      display: flex;
      align-items: center;
      background: #f2f3f5;
      padding: 0 12px;
      justify-content: space-between;
      input {
        border: none;
        background: transparent;
        width: 90px;
      }
      input:focus {
        outline: none;
        border: none;
      }
      .btn {
        min-width: 72px;
        color: #3c80ff;
        cursor: default;
      }
    }
    .modify-input {
      margin-bottom: 20px;
      width: 100%;
      height: 32px;
      display: flex;
      align-items: center;
      background: #f2f3f5;
      padding: 5px 14px;
      input {
        width: 100%;
        border: none;
        background: transparent;
      }
      input:focus {
        outline: none;
        border: none;
      }
      .btn {
        width: 72px;
        color: #3c80ff;
      }
    }
  }
  .dialog-footer {
    display: flex;
    justify-content: flex-end;
    padding: 24px 32px;
    border-top: 1px solid #e0e0e0;

    .confirm-btn {
      background: #3c80ff;
      box-shadow: 0px 2px 2px 0px rgba(22, 93, 255, 0.6);
      border-radius: 2px 2px 2px 2px;
      padding: 8px 29px;
    }
    .cancel-btn {
      background: #f2f3f5;
      color: #86909c;
      border-radius: 2px 2px 2px 2px;
      padding: 8px 29px;
      margin-right: 10px;
    }
  }
}
</style>
